package com.platform.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 编辑商品:所有商品
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ProductEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private String name;
    private String productUrl;
    private Integer type;//类型:1价格产品2兑换产品3余额兑换4Done-one产品
    private String typeName;
    private String banners;
    private List<String> bannerArr;
    private BigDecimal price;
    private BigDecimal oldPrice;
    private BigDecimal spcPrice;
    private Integer number;
    private Integer sales;
    private Integer statu;
    private String describ;
    private String imageList;
    private String body;
    private String other;
    private String other1;
    private String other2;
    private Date createDate;
    private Integer version;
    private Integer merchantId;
    private String merchantName;
    private Long cateL1;
    private Long cateL2;
    private List<ProStyleEntity> proStyles;
    private List<String> select;
    private String receive;
    private String payWay;
    private String cateL1Name;
    private String cateL2Name;
    private Integer auditStatus;
    private String content;
    private BigDecimal rate;//手续费率
    private BigDecimal giveEnergy;//赠送能量
    private BigDecimal spcFree;//释放spc
    private BigDecimal giveTeam;//团队奖励利率

    public BigDecimal getGiveEnergy() {
        return giveEnergy==null?BigDecimal.ZERO:giveEnergy;
    }

    public void setGiveEnergy(BigDecimal giveEnergy) {
        this.giveEnergy = (giveEnergy == null ? BigDecimal.ZERO : giveEnergy);
    }

    public BigDecimal getSpcFree() {
        return spcFree==null?BigDecimal.ZERO:spcFree;
    }

    public void setSpcFree(BigDecimal spcFree) {
        this.spcFree = (spcFree == null ? BigDecimal.ZERO : spcFree);
    }

    public String getReceive(){
        if(select != null && select.size()>0){
            Collections.sort(select);
            return select.stream().collect(Collectors.joining(","));
        }
        return null;
    }

    public List<String> getWay(){
        List<String> strings = new ArrayList<>();
        if(this.payWay.contains(",")){
            String[] split = this.payWay.split(",");
            strings = Arrays.asList(split);
            return strings;
        }
        strings.add(this.payWay);
        return strings;
    }
    public List<String> getBannerList(){
        List<String> strings = new ArrayList<>();
        if(StringUtils.isEmpty(this.banners)){
            return strings;
        }
        if(this.banners.contains(",")){
            String[] split = this.banners.split(",");
            strings = Arrays.asList(split);
            return strings;
        }
        strings.add(this.banners);
        return strings;
    }


}
